package com.lujieni.springbootsecurity.controller;

import com.lujieni.springbootsecurity.po.UserDO;
import com.lujieni.springbootsecurity.service.LoginService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.security.PermitAll;
import javax.servlet.http.HttpServletRequest;

/**
 * @Author：小鹿爱吃鱼
 * @Date: 2025/5/29 14:31
 * @Description:
 */
@RestController
@RequiredArgsConstructor
public class LoginController {

    private final LoginService loginService;

    @PostMapping(value = "/login")
    @PermitAll
    public String login(@RequestBody UserDO user) {
        return loginService.login(user.getUserName(), user.getPassword());
    }

    @PostMapping(value = "/hey")
    public String hey() {
        return "hey";
    }

    /**
     *  权限配置里logout().disable()加了后 @PermitAll才生效
     * @return
     */
    @PostMapping(value = "/logout")
    public void logout(HttpServletRequest request) {
        loginService.logout(request);
    }


}
